package com.movitech.mobile.cz.base.purchase.controller;


import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.plugins.Page;
import com.movitech.mobile.cz.base.purchase.bizvo.StrategicProtocolListReqVO;
import com.movitech.mobile.cz.base.purchase.entity.WStrategicProtocol;
import com.movitech.mobile.cz.base.purchase.service.WStrategicProtocolService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
/**
 * <p>
 * WStrategicProtocol 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@RestController
@RequestMapping("/v1/wStrategicProtocol")
@Api(value = "战略采购协议基础操作接口", description = "战略采购协议基础操作接口")
public class WStrategicProtocolController {
    @Autowired
    private WStrategicProtocolService wStrategicProtocolService;

    @GetMapping("/allList")
    @ApiOperation(
            value = "获取所有战略采购协议接口",
            notes = "获取所有战略采购协议接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult list() {
        RestReturnResult restResult = RestReturnResult.success();
        Page<WStrategicProtocol> page = wStrategicProtocolService.selectPage(new Page<WStrategicProtocol>());
        restResult.setData(page);
        return restResult;
    }

    @PostMapping("/searchList/{pageNumber}")
    @ApiOperation(
            value = "战略采购协议列表查询接口",
            notes = "战略采购协议列表查询接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult searchList(@RequestBody WStrategicProtocol wStrategicProtocol,
                @ApiParam(value = "分页页数")@PathVariable Integer pageNumber) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<WStrategicProtocol> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(wStrategicProtocol);
        page = wStrategicProtocolService.selectPage(page,wrapper);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getWStrategicProtocol/{id}")
    @ApiOperation(
            value = "战略采购协议对象ID获取接口",
            notes = "战略采购协议对对象ID获取接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult getWStrategicProtocol(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        restResult = wStrategicProtocolService.getWStrategicProtocol(id);
        return restResult;
    }

    @PostMapping("/add")
    @ApiOperation(
            value = "战略采购协议添加接口",
            notes = "战略采购协议添加接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult add(@RequestBody WStrategicProtocol wStrategicProtocol) {
        RestReturnResult restResult = RestReturnResult.success();
        wStrategicProtocolService.insert(wStrategicProtocol);
        restResult.setData(wStrategicProtocol);
        return restResult;
    }

    @PutMapping("/update")
    @ApiOperation(
            value = "战略采购协议更新接口",
            notes = "战略采购协议更新接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult update(@RequestBody WStrategicProtocol wStrategicProtocol) {
        RestReturnResult restResult = RestReturnResult.success();
        wStrategicProtocolService.updateById(wStrategicProtocol);
        restResult.setData(wStrategicProtocol);
        return restResult;
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(
            value = "战略采购协议通过ID删除接口",
            notes = "战略采购协议通过ID删除接口",
            response = WStrategicProtocol.class
    )
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        wStrategicProtocolService.deleteById(id);
        return restResult;
    }
    
    
    @PutMapping("/searchStrategicProtocolList")
    @ApiOperation(value = "战略采购协议列表查询", notes = "战略采购协议")
    public RestReturnResult searchStrategicProtocolList(@RequestBody StrategicProtocolListReqVO strategicProtocolListReqVO){
    	RestReturnResult restResult = RestReturnResult.success();
    	restResult = wStrategicProtocolService.searchStrategicProtocolList(strategicProtocolListReqVO);
        return restResult;
    }


}

